//题目:
// 实现一个MyQueue类，该类用两个栈来实现一个队列。
#include<iostream>
#include<stack>

using namespace std;
//代码:
class MyQueue 
{
public:
    /** Initialize your data structure here. */
    stack<int> st1,st2;
    MyQueue() {}   
    
    /** Push element x to the back of queue. */
    void push(int x) 
    {
        st1.push(x);
    }
    
    /** Removes the element from in front of queue and returns that element. */
    int pop() 
    {
        if(st2.empty())
        {
            //将st1中的数据倒给st2
            while(!st1.empty())
            {
                st2.push(st1.top());
                st1.pop();
            }
        }
        int ret=st2.top();
        st2.pop();
        return ret;
    }
    
    /** Get the front element. */
    int peek() 
    {
        if(st2.empty())
        {
            //将st1中的数据倒给st2
            while(!st1.empty())
            {
                st2.push(st1.top());
                st1.pop();
            }
        }
        return st2.top();
    }
    
    /** Returns whether the queue is empty. */
    bool empty() 
    {
        if(st2.empty())
        {
            //将st1中的数据倒给st2
            while(!st1.empty())
            {
                st2.push(st1.top());
                st1.pop();
            }
        }
        return st2.empty();    
    }
};